/*function addCart(commodity_ID){
    window.location.href='cart.do?operate=addcart&commodity_ID='+commodity_ID;
}*/
window.onload=function (){
    var vue = new Vue({
        el:"#index_div",
        data:{
            commoditylist:{},
            "kind":1,
            Key:"",

        },
        methods:{
            getCommodity:function (){
                axios({
                    method:"POST",
                    url:"Commodity.do",
                    params:{
                        operate:'indexInfo'
                    }
                })
                    .then(function (value) {
                        var commoditylist = value.data ;
                        vue.commoditylist = commoditylist ;

                    })
                    .catch(function (reason) {});
            },
            addCart:function (commodity_ID) {
                if(confirm(
                    '确定要加入购物车吗?(重复加入购物车则数量+1)'))
                {
                    axios({
                        method:"POST",
                        url:"cart.do",
                        params:{
                            operate:'addcart',
                            commodity_ID : commodity_ID,
                        }
                    })

                    .then(function (value) {
                        vue.getCommodity();
                        vue.getKind();

                    })
                    .catch(function (reason) {});
            }
            },
            getKind:function () {
                axios({
                    method:"POST",
                    url:"cart.do",
                    params:{
                        operate:'getkind',
                    }
                })
                    .then(function (value) {
                        var kind = value.data ;
                        vue.kind = kind ;
                       /* var kindStr = JSON.stringify(kind);
                        alert(kindStr);*/

                    })
                    .catch(function (reason) {});
            },
            onSubmit:function () {
                axios({
                    method:"POST",
                    url:"Commodity.do",
                    params:{
                        operate:'indexInfo',
                        key: vue.Key,
                    }
                })
                    .then(function (value) {
                        var commoditylist = value.data ;
                        vue.commoditylist = commoditylist ;
                        /* var kindStr = JSON.stringify(kind);
                         alert(kindStr);*/

                    })
                    .catch(function (reason) {});
            }
        },
        beforeMount:
            function(){
                this.getCommodity() ;
                this.getKind();
            }
    });
}